#include "udpcontrol.h"
#include "ui_udpcontrol.h"

UdpControl::UdpControl(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::UdpControl)
{
    ui->setupUi(this);

    //绑定  --- 自动绑定
    msocket.bind(QHostAddress::AnyIPv4,9999);
    //关联读数据信号readyRead  -- 接收广播数据
    connect(&msocket,&QUdpSocket::readyRead,this,&UdpControl::recv_broadcast);

}

UdpControl::~UdpControl()
{
    delete ui;
}

void UdpControl::recv_broadcast()
{
    QHostAddress appaddr;
    quint16 port;
    QByteArray array;  //要另外分配空间
    array.resize(100);   //分配空间
    msocket.readDatagram(array.data(),array.size(),&appaddr,&port);

    //给发送放回馈数据-- 给app端发送数据
    msocket.writeDatagram("ip",3,appaddr,port);



}






















